import {
	reactive,
	ref
} from "vue";

import {uploadFile} from "@/network/home.js"


export default function() { // 导出一个默认方法
	const fileList = ref([]);

	const deletePic = (index) => {
		fileList.value.splice(index, 1);
	};
	
	const afterRead = async (event) => {
	  // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
	  let lists = [].concat(event.file);
	  let fileListLen = fileList.value.length;
	  lists.map((item) => {
	    fileList.value.push({
	      ...item,
	      status: 'uploading',
	      message: '上传中',
	    });
	  });
	  for (let i = 0; i < lists.length; i++) {
	    const result = await uploadFile(lists[i].url);
	    let item = fileList.value[fileListLen];
	    fileList.value.splice(fileListLen, 1, {
	      ...item,
	      status: 'success',
	      message: '',
	      url: result.data.fullurl,
		  urls: result.data.url,
	    });
	    fileListLen++;
	  }
	};




	return {
		deletePic,
		afterRead,
		fileList
	} // 方法返回宽高值
}